zabbix_agent_source:
  file.managed:
    - name: /tmp/zabbix24-agent-2.4.2-2.1.x86_64.rpm
    - unless: test -e /tmp/zabbix24-agent-2.4.2-2.1.x86_64.rpm
    - user: root
    - goup: root
    - makedirs: True
    - source: salt://zabbix_agent/file/zabbix24-agent-2.4.2-2.1.x86_64.rpm
 
zabbix_agent_install:
  cmd.run:
    - cwd: /tmp
    - names:
      - zypper -n --gpg-auto-import-keys  install /tmp/zabbix24-agent-2.4.2-2.1.x86_64.rpm
    - unless: test -d /etc/zabbix
    - require:
      - file: zabbix_agent_source

zabbix_agent_conf:
  file.managed:
    - name: /etc/zabbix/zabbix-agentd.conf
    - source: salt://zabbix_agent/file/zabbix-agentd.conf
    - requires:
      - zabbix_agent_install

zabbix_agent_service:
  cmd.run:
    - names:
      - /sbin/chkconfig zabbix-agentd on
    - unless: /sbin/chkconfig --list zabbix-agentd
  service.running:
    - name: zabbix-agentd
    - enable: True
    - restart: True
    - watch:
      - file: /etc/zabbix/zabbix-agentd.conf
